<template>
    <h2>登录页面</h2>
    <table border="1">
        <tr>
            <td>用户名</td>
            <td><input type="text" v-model="info.Uname" /></td>
        </tr>
        <tr>
            <td>密码</td>
            <td><input type="password" v-model="info.Upwd"/></td>
        </tr>
        <tr>
            <td colspan="2">
                <button @click="Ulogin">登录</button>
            </td>
        </tr>
    </table>
</template>
<script setup lang="ts">
import axios from 'axios';
import {ref} from 'vue'
import{useRouter} from 'vue-router'
const router = useRouter()
const info = ref({
    Uname: '',
    Upwd: ''
})
const Ulogin = () => {
    axios.get('https://localhost:44396/api/UserRole/UserLogin',
        {
            params: {
                Uname: info.value.Uname,
                Upwd: info.value.Upwd
            }
        }
    ).then(res=>{
        if(res.data.re==1){
            alert("管理员登录成功")
            router.push("/AddUser")
        }else if(res.data.re==2){
            alert("用户已登录")
            router.push(
                {
                    path:"ShowUserInfo",
                    query:{
                        Uid:res.data.Uid
                    }
                }
            )
        }else if(res.data.re==-1){
            alert("用户名不存在")
        }else if(res.data.re==-2){
            alert("密码错误")
        }else{
            alert("登录失败")
        }
    }).catch(err=>{
        console.log(err);
    })
}

</script>